package juc;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class Phone implements Runnable{
    Lock lock = new ReentrantLock();
    @Override
    public void run() {
        sendSMS();
    }
    void sendSMS(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"send sms");
            sendEmail();
        }finally {
            lock.unlock();
        }
    }
    void sendEmail(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"send email");
        }finally {
            lock.unlock();
        }
    }
}

public class ReLock {
    public static void main(String[] args) {
        Phone phone = new Phone();
        Thread t1 = new Thread(phone,"t1");
        Thread t2 = new Thread(phone,"t2");
        t1.start();
        t2.start();
    }
}
/*
t1send sms
t1send email
t2send sms
t2send email
 */
